home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Internet Tools 1993 July / Internet Tools.iso / RockRidge / info-service / prospero / PRM / src / testprog / longsend.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-04-24  |  2.4 KB  |  98 lines

  1. /*
  2.  * Copyright (c) 1992, 1993 by the University of Southern California
  3.  *
  4.  * For copying and distribution information, please see the files
  5.  * <prm-copyr.h>.
  6.  */
  7.  
  8. #include <prm-copyr.h>
  9.  
  10.  
  11. #include <stdio.h>
  12. #include <sys/time.h>
  13. #include <sys/resource.h>
  14. #include <sys/times.h>
  15.  
  16. #define  MAIN_PROG
  17. #include <comm.h>   /*     This file defines certain constants, and declares
  18.             some global variables used by the message passing
  19.             routines.  */
  20.  
  21. #define SENDTO_PORT 1                     /* Port_id on destination task */
  22. #define RCVON_PORT  1                     /* Port on which to rcv messages */
  23.  
  24. char *progname;
  25.  
  26. main(argc, argv)
  27. int argc;
  28. char **argv;
  29. {
  30.   int ntasks, my_tid, npkts;
  31.   int time_dcrmt, timeleft, iter_cnt;
  32.   int sendto_task, nbytes, rbytes;
  33.   int time_secs, time_usecs, rcv_len;
  34.   double time;
  35.   char *a;
  36.   char fname[32];
  37.   struct rusage rusage1, rusage2;
  38.   FILE *ifd, *ofd;
  39.   register int i;
  40.  
  41.   init_task(argv);    /* Initialization is required for all tasks in every
  42.              application */
  43.   
  44.   pfs_debug=0;
  45.   my_tid = gettid(); 
  46.   if (my_tid == -1) {
  47.     io_printf(" task could not get its tid!", (char *)0);
  48.     exit(1);
  49.   }
  50.   
  51.   if( (ifd = fopen("longsend.in", "r")) == NULL) {
  52.     perror("fopen longsend.in");
  53.     exit(1);
  54.   }
  55.   fscanf(ifd, "%d %d", &npkts, &iter_cnt);
  56.   nbytes = npkts * PRM_APPL_MSG_LEN;
  57.   a = (char *)malloc(nbytes);
  58.   
  59.   if (my_tid == 1) { 
  60.     vsend(2, SENDTO_PORT, ANY_TAG, a, 4); 
  61.     
  62.     getrusage(RUSAGE_SELF, &rusage1);
  63.     for (i = 1; i<= iter_cnt; i++)  {
  64.       io_printf("iter %d: sending long message (%d bytes) to task 2", 
  65.         i, nbytes);
  66.       vsend(2, SENDTO_PORT, ANY_TAG, a, nbytes); 
  67.     }
  68.     getrusage(RUSAGE_SELF, &rusage2);
  69.     
  70.  
  71.     time = (double) ((rusage2.ru_utime.tv_sec - rusage1.ru_utime.tv_sec) +
  72.               (rusage2.ru_stime.tv_sec - rusage1.ru_stime.tv_sec) ) +
  73.             ((double)((rusage2.ru_utime.tv_usec - 
  74.                    rusage1.ru_utime.tv_usec) +
  75.                   (rusage2.ru_stime.tv_usec -
  76.                    rusage1.ru_stime.tv_usec)) 
  77.              ) / 1.0E+6;
  78.     sprintf(fname, "long_timings_%d", nbytes);
  79.     ofd = fopen(fname, "a");
  80.     fprintf(ofd, "%d\t %f \n", iter_cnt, time);
  81.     fclose(ofd);
  82.   }
  83.   
  84.   else {
  85.     vrecv(ANY_TASK, RCVON_PORT, ANY_TAG, a, 4);
  86.  
  87.     for (i=1; i<= iter_cnt; i++) {
  88.       rcv_len = vrecv(ANY_TASK, RCVON_PORT, ANY_TAG, a, nbytes);
  89.       io_printf("iter %d: Rcvd long message (%d bytes)", 
  90.         i, rcv_len, (char *)0);
  91.     }      
  92.   }
  93.   
  94.   io_printf("done", (char *)0);
  95.   exit(0);
  96. }
  97.  
  98.